<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include ('../global/initialize.php');

aos_header('History overview');

$turn = getCurrentTurn();
?>				
					<link type="text/css" rel="stylesheet" href="../global/yui/calendar/assets/skins/sam/calendar.css">
					<link type="text/css" rel="stylesheet" href="../global/yui/button/assets/skins/sam/button.css" >
<?php

print_history_tab('Overview');
?>
					<div class="blok contains-calendar">
						<h2><?php transprint( 'Overview' ); ?></h2><br />
						<br />
						<div class="floatleft yui-skin-sam">
							<div id="history-calendar"></div>
						</div>
						<div class="floatright history-item-container">
							<strong id="history-item-list-title"><?php transprint( 'No date selected' ); ?></strong>
							<div id="history-item-list-hidden" class="hidden">&nbsp;</div>
							<div id="history-item-list">
								&nbsp;
							</div>
						</div>
<?php

//    $query2 = "SELECT date " .
//    		"FROM history " .
//    		"WHERE turn <= $turn AND visible = 1 " .
//    		"ORDER BY turn DESC LIMIT 1";
//    $result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
//	$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
$max_date = getCurrentDate();
$max_date = split('-', $max_date);
$page_date = $max_date[1] . "/" . $max_date[2];
$max_date = $max_date[1] . "/" . $max_date[0] . "/" . $max_date[2];

$query2 = "SELECT date " .
"FROM history " .
"WHERE turn <= $turn AND visible = 1 " .
"ORDER BY turn ASC LIMIT 1";
$result2 = mysql_query($query2) or die("Query failed : " . mysql_error());
$row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
$min_date = $row2['date'];
$min_date = split('-', $min_date);
$min_date = $min_date[1] . "/" . $min_date[0] . "/" . $min_date[2];
$min_date = '01/01/1750';

$query = "SELECT date " .
"FROM history " .
"WHERE visible = 1 AND turn <= $turn " .
"ORDER BY turn DESC";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num = mysql_numrows($result);
$i = 0;
$selected = "";
while ($i < $num) {
	if ($selected != '') {
		$selected .= ",";
	}
	$date = split('-', mysql_result($result, $i, "date"));
	$selected .= $date[1] . "/" . $date[0] . "/" . $date[2];
	$i++;
}
?>					
					</div>
<?php

$javascript = "<script language=\"javascript\">\n
							var calendar; 
							function init() { 
							   calendar = new YAHOO.widget.Calendar( \"calendar\", 
							                               \"history-calendar\", 
							                                { pagedate: \"$page_date\",
							                                  MULTI_SELECT: true, 
							                                  mindate: \"$min_date\",
							                                  maxdate: \"$max_date\",
							                                  selected: \"$selected\" } ); 
							   calendar.render();
							   calendar.selectEvent.subscribe( selectDate, calendar, true );
							   calendar.deselectEvent.subscribe( deselectDate, calendar, true );
							}
							YAHOO.util.Event.addListener( window, 'load', init ); 	
						</script>\n";
aos_footer($javascript);
?>
